//
//  NSMutableArray+category.m
//  XOWMSDK
//
//  Created by tucici on 2017/12/2.
//  Copyright © 2017年 SKL. All rights reserved.
//

#import "NSMutableArray+category.h"
#import "NSDictionary+category.h"
#import "NSString+category.h"
@implementation NSMutableArray (category)
- (void)yjd_enumerate:(NSDictionary *)dict
{
    NSString *jsonString = [dict yjd_json];
    
    //如果已经有缓存
    if ([self count] > 0)
    {
        __block BOOL containt = NO;
        //遍历缓存，看是否存在相同账号(账号更改密码，缓存最新的密码)
        [self enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSString *objString = (NSString *)obj;
            NSMutableDictionary *newDict = [NSMutableDictionary dictionaryWithDictionary:[objString yjd_dict]];
            NSString *cachedKey = [[newDict allKeys] firstObject];
            NSString *newKey = [[dict allKeys] firstObject];
            if ([cachedKey isEqualToString:newKey])
            {
                containt = YES;
                [newDict setObject:[dict objectForKey:newKey] forKey:cachedKey];
                NSString *newJsonString = [newDict yjd_json];
                [self removeObject:obj];
                [self insertObject:newJsonString atIndex:0];
                *stop = YES;
            }
        }];
        //缓存中，不存在新账号
        if (containt == NO)
        {
            [self insertObject:jsonString atIndex:0];
        }
    }
    //如果没有缓存
    else
    {
        [self addObject:jsonString];
    }
}


- (void)sp_didGetInfoSuccess {
    NSLog(@"Get Info Success");
}
@end
